//
//  YMJTableViewCell.m
//  010-自适应高度
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "YMJTableViewCell.h"

@interface YMJTableViewCell ()
@property (nonatomic, strong) UILabel *labelYMJ;
@end
@implementation YMJTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _labelYMJ = [[UILabel alloc] init];
        [self.contentView addSubview:_labelYMJ];
        _labelYMJ.textColor = [UIColor colorWithRed:(arc4random() % 256) / 255.0 green:(arc4random() % 256) / 255.0 blue:(arc4random() % 256) / 255.0 alpha:1];
        _labelYMJ.numberOfLines = 0;
        _labelYMJ.font = [UIFont systemFontOfSize:17];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    _labelYMJ.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.frame.size.height);
    /**NSLog(@"contentView_________%f",self.contentView.frame.size.height);
    NSLog(@"self=========%f",self.frame.size.height);*/
    //contentView_________的高度比self=========的高度少一点,所以自适应label高度时要已self.frame.size.height 为准
    // 同理自适应宽度,字体大小,也要一致相同.不然不一样.
}
- (void)setString:(NSString *)string {
    _string = [string copy];
    // 先copy在赋值,不要偷懒
    _labelYMJ.text = _string;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
